<template>
    <div>
<!--        顶部滑动条区域-->
        <div id="slider" class="mui-slider nav-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id === 1?'mui-active': '']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="item in cates" :key="item.id" @tap="getPhotoListBycateId(item.id)">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
<!--        图片列表区域-->
        <ul class="phto-list">
            <router-link v-for="item in listImg" :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>
    import mui from '../../../lib/mui/js/mui.min.js'//导入muijs
    export default {
        name: "PhotoList.vue",

        data(){
            return {
                cates : [],//所有分类的列表
                listImg : [],
            };
        },
        mounted() {//当组件中的Dom结构被渲染好并放到页面中后，会执行这个钩子函数
            // //初始化滑动控件
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        created(){
            this.getAllCategory();
            this.getPhotoListBycateId(1);
        },
        methods : {
            getAllCategory(){
                //获取所有的图片分类
                this.axios.get('/api/getimgcategory').then(result => {
                    if(result.status === 200){
                        //手动拼接出一个最完整的分类列表
                        result.data.unshift({title:"全部", id : 1});
                        this.cates = result.data;
                    }
                })
            },
            getPhotoListBycateId(cateId){
                //根据 分类Id，获取图片列表
                this.axios.get('/api/getimages/'+cateId).then(result => {
                    if(result.status === 200){
                        this.listImg = result.data;
                    }
                })
            },
        }
    }
</script>

<style scoped lang="scss">
    *{
        touch-action: pan-y;
        .nav-slider{
            background-color: #fff;
        }
        img[lazy=loading] {
            width: 40px;
            height: 300px;
            margin: auto;
        }
        .phto-list{
            width: 100%;
            list-style: none;
            padding: 0px 5px;
            > li{
                width: 96%;
                margin: 5px auto;
                transition: all .5s;
                position: relative;
                img{
                    width: 100%;
                    display: inline-block;
                }
                &:hover{
                    width: 100%;
                }
                .info{
                    width: 100%;
                    color: #ccc;
                    text-align: left;
                    position: absolute;
                    bottom: 5px;
                    left: 0;
                    max-height: 80px;
                    overflow: hidden;
                    background-color: rgba(0, 0, 0, .5);
                    padding:0px 5px;
                    .info-title{
                        font-size:14px;
                    }
                    .info-body{
                        font-size: 13px;
                    }
                }
            }

        }
    }


</style>